#!/bin/sh
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

#Tom rad till stdout (log)
echo
#Skicka markering för att nytt påbörjas
echo "^NEW RUN: Install"
#Skicka datum till stdout (log)
/bin/date
#Uppdatera paketlista
/usr/bin/apt-get update
if [ $? != 0 ]; then
	#Misslyckades, testa igen om 5min
	echo "Try again, waiting 10sek"
	sleep 10
	/usr/bin/apt-get update
	ret="$?"
	if [ $ret != 0 ]; then
		#Misslyckades, meddela
		echo "Exiting with error ($ret)"
		exit
	fi
fi

#Installera / Avinstallera paket
/usr/bin/apt-get install -y --allow-unauthenticated $@
if [ $? != 0 ]; then
	#Misslyckades, testa igen om 5min
	echo "Try again, waitning 10sek"
	sleep 10
	/usr/bin/apt-get install -y --allow-unauthenticated $@
	ret="$?"
	if [ $ret != 0 ]; then
		#Misslyckades, meddela
		echo "Exiting with error ($ret)"
		exit
	fi
fi
#Rensa bort nerladdade paket
/usr/bin/apt-get clean
